using System;
using System.Collections.Generic;
using System.Text;

namespace Serialization
{
    public class SerializationInfo : IEnumerable<SerializationMemberInfo>
    {
        private SerializationMemberInfoCollection _data;
        private Type _type;

        public SerializationInfo(Type t)
        {
            _type = t;
            _data = new SerializationMemberInfoCollection();
        }

        public int Count
        {
            get { return _data.Count; }
        }

        public Type Type
        {
            get { return _type; }
        }

        public void AddValue<T>(string name, T value)
        {
            _data.Add(new SerializationMemberInfo(name, value, typeof(T)));
        }

        public void AddValue(string name, object value, Type type)
        {
            _data.Add(new SerializationMemberInfo(name, value, type));
        }

        public object GetValue(string name)
        {
            if (_data.Contains(name))
            {
                return _data[name].Value;
            }
            return null;
        }

        public T GetValue<T>(string name)
        {
            if (_data.Contains(name))
            {
                return (T)_data[name].Value;
            }
            return default(T);
        }

        #region IEnumerable<SerializationMemberInfo> Members

        public IEnumerator<SerializationMemberInfo> GetEnumerator()
        {
            return _data.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return ((System.Collections.IEnumerable)_data).GetEnumerator();
        }

        #endregion
    }
}
